﻿Imports System.Data.OleDb
Public Class View_Table
    Dim con As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim da As OleDbDataAdapter
    Dim mystring(9) As String
    Public Sub filldatagridview(ByVal qry As String, ByVal constr As String, ByVal type As String, ByVal tablename As String)
        Try
            con = New OleDbConnection(constr)
            con.Open()
            Me.Text = tablename
            mystring = New String() {"SELECT", "WHERE", "FROM", "GROUP BY", "ORDER BY", "INSERT", "DELETE", "UPDATE", "ALTER", "SET"}
            fillcolor()
            da = New OleDbDataAdapter(qry, con)
            Dim ds As New DataSet()
            da.Fill(ds, tablename)
            DataGridView1.DataSource = ds
            DataGridView1.DataMember = tablename
            Me.Show()
            lblquery.Text = qry
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub
    Public Sub fillquery(ByVal str As String)
        Try
            da = New OleDbDataAdapter(str, con)
            Dim ds As New DataSet()
            da.Fill(ds, Me.Text)
            DataGridView1.DataSource = ds
            DataGridView1.DataMember = Me.Text
            Me.Show()
            lblquery.Text = str
            Me.Text = Me.Text
            fillcolor()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub fillxml(ByVal ds As DataSet, ByVal table As String)
        Try
            DataGridView1.DataSource = ds.Tables(0)
            lblquery.Text = "SELECT * FROM " & table
            lblquery.EnableAutoDragDrop = False
            Me.Show()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub fillcolor()
        Dim i As Integer
        While i <= 8
            If lblquery.Find(mystring(i)) > 0 Then
                Dim my1stPosition As Integer = InStr(lblquery.Text, mystring(i))
                If my1stPosition Then
                    lblquery.Focus()
                    lblquery.SelectionStart = my1stPosition - 1
                    lblquery.SelectionLength = Len(mystring(i))
                    lblquery.SelectionColor = Color.Blue
                End If
            End If
            i = i + 1
        End While
        lblquery.SelectionStart = lblquery.TextLength
    End Sub

    Private Sub btnquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnquery.Click
        Dim a As New Query_Form
        a.gt(Me.lblquery)
    End Sub

    Private Sub lblquery_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblquery.TextChanged
        fillquery(lblquery.Text)
        fillcolor()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As New View_Report
        a.MdiParent = Parent1
        a.fillreport(lblquery.Text, con.ConnectionString, Me.Text)
    End Sub
End Class